/*
 * @Author: Hunter
 * @Date: 2022-02-11 15:41:05
 * @LastEditTime: 2022-05-01 20:23:12
 * @LastEditors: Hunter
 * @Description: 
 * @FilePath: \book_mark\src\utils\storage.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */
// const { ctx, proxy } = getCurrentInstance()
export declare interface IStorage {
    setStorage(key: string, val: any): void
    getStorage(key: string): any
    clearStorage(key: string): void
}
export class Storage implements IStorage {
    setStorage(key: string, val: any) {
        try {
            localStorage.setItem(key, JSON.stringify(val))
        }
        catch (error) {
            console.error(error)
        }
    }
    getStorage(key: string) {
        try {
            const str = localStorage.getItem(key)
            if (str === null || str === undefined) {
                return
            }
            return JSON.parse(str)
        } catch (error) {
            console.error(error);
            return null
        }
    }
    clearStorage(key: string) {
        try {
            key && localStorage.removeItem(key);
            !key && localStorage.clear();
        } catch (error) {
            console.error(error);
        }
    }
}